package Thread;

import java.util.concurrent.BlockingQueue;
import java.util.concurrent.LinkedBlockingDeque;

public class Dom29 {
    public static void main(String[] args) {

        BlockingQueue<Integer> queue=new LinkedBlockingDeque<>(1000);
        //生产者
        Thread producer =new Thread(()->{
            int  n=0;
            while (true){
                try{
                    queue.put(n);
                    System.out.println("生产者" + n);
                    n++;
                }catch (InterruptedException e){
                    throw new RuntimeException();
                }
            }

        },"producer");
          //消费者
        Thread consumer=new Thread(()->{
             while (true){
                 try {
                    Integer n= queue.take();
                     System.out.println("消费者"+n);
                 }catch (InterruptedException e){
                     throw new RuntimeException();
                 }
             }
        },"consumer");
        producer.start();
        consumer.start();
    }
}
